/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package priority;

/**
 *
 * @author TQNINH
 */
public class SetPriority {

    public SetPriority(){
        
    }
    
    private static Runnable makeRunnable(){
        Runnable r = new Runnable(){
            
            public void run(){
                for(int i = 0;i < 5;i++){
                    Thread t = Thread.currentThread();
                    System.out.println("In run() - Priority = " +
                            t.getPriority() + ", Name = " + t.getName());
                    try{
                        Thread.sleep(2000);
                    } catch(InterruptedException ex) {
                        ex.printStackTrace();
                    }
                }
            }
        };
        return r;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        System.out.println("\nBusiness Priorities:\n");
        Thread threadA = new Thread(makeRunnable(), "Meeting deadlines " +
                "for the project.");
        threadA.setPriority(8);
        
        threadA.start();
        
        Thread threadB = new Thread(makeRunnable(), "Effort variance " +
                "for the project.");
        threadB.setPriority(2);
        
        threadB.start();
        
        Runnable r = new Runnable(){
            public void run(){
                Thread threadC = new Thread(makeRunnable(), "Schedule variance " +
                        "for the project.");
                threadC.start();
            }
        };
        
        Thread threadD = new Thread(r, "Schedule variance for the project.");
        threadD.setPriority(7);
        threadD.start();
        
        try{
            Thread.sleep(6000);
        } catch(InterruptedException ex) {
            ex.printStackTrace();
        }
        
        threadA.setPriority(3);
        System.out.println("In main() - Meeting deadlines.getPriority()= " +
                threadA.getPriority());
    }
}
